{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "import os \n",
    "from os.path import join,split, exists\n",
    "import PIL\n",
    "import cv2\n",
    "import glob\n",
    "from img_utils import  * \n",
    "\n",
    "import IPython\n",
    "import OpenEXR\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "from PIL import  Image\n",
    "from tqdm import tqdm \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "GIF saved at: logs/000000.png\n",
      "GIF saved at: logs/000001.png\n",
      "GIF saved at: logs/000002.png\n",
      "GIF saved at: logs/000003.png\n",
      "GIF saved at: logs/000004.png\n",
      "GIF saved at: logs/000005.png\n",
      "GIF saved at: logs/000006.png\n",
      "GIF saved at: logs/000007.png\n"
     ]
    }
   ],
   "source": [
    "src_path = \"/baai-cwm-1/baai_cwm_ml/public_data/rendering_data/3diclight/3diclight/renders_3diclightv3_eevee/0a0ceee64fa0ca2084799c38e79049c571eb7cae22b3d40a9c23597625485a9d\"\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "object_ids = os.listdir(src_path)\n",
    "\n",
    "for idx,o in enumerate(object_ids):\n",
    "    print('processing %d-th objects')\n",
    "\n",
    "    imgs = sorted(glob.glob(join(src_path,o, '*.png')))\n",
    "\n",
    "    images_to_gif(imgs,output_gif = 'logs/%06d.gif'%(idx), duration = 20)\n",
    "\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "imgs = glob.glob('/baai-cwm-1/baai_cwm_ml/cwm/shaocong.xu/exp/tools/logs/*png')\n",
    "for x in imgs:\n",
    "    os.rename(x,x.replace('png','gif'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "GIF saved at: logs/error.gif\n"
     ]
    },
    {
     "ename": "TypeError",
     "evalue": "'module' object is not callable",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[2], line 5\u001b[0m\n\u001b[1;32m      2\u001b[0m imgs \u001b[38;5;241m=\u001b[39m \u001b[38;5;28msorted\u001b[39m(glob\u001b[38;5;241m.\u001b[39mglob(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m/baai-cwm-1/baai_cwm_ml/cwm/hong.li/code/3dgen/data/data_factory_blender/datasets/5daigc/renders_5daigc_v1/eevee/f32e9c10a3cbbd781e8b383b9e44f77894a61749dd77164b9956d6a388062fcd/*png\u001b[39m\u001b[38;5;124m\"\u001b[39m))\n\u001b[1;32m      4\u001b[0m images_to_gif(imgs,output_gif \u001b[38;5;241m=\u001b[39m out_name, duration \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m20\u001b[39m)\n\u001b[0;32m----> 5\u001b[0m \u001b[43mImage\u001b[49m\u001b[43m(\u001b[49m\u001b[43murl\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mout_name\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m      8\u001b[0m \u001b[38;5;66;03m# imgs2video(imgs, fps= 10 , out_path= 'tmp.mp4')\u001b[39;00m\n",
      "\u001b[0;31mTypeError\u001b[0m: 'module' object is not callable"
     ]
    }
   ],
   "source": [
    "\n",
    "out_name = 'logs/error.gif'\n",
    "imgs = sorted(glob.glob(\"/baai-cwm-1/baai_cwm_ml/cwm/hong.li/code/3dgen/data/data_factory_blender/datasets/5daigc/renders_5daigc_v1/eevee/f32e9c10a3cbbd781e8b383b9e44f77894a61749dd77164b9956d6a388062fcd/*png\"))\n",
    "\n",
    "images_to_gif(imgs,output_gif = out_name, duration = 20)\n",
    "\n",
    "\n",
    "IPython.display.Image(url= out_name)\n",
    "# imgs2video(imgs, fps= 10 , out_path= 'tmp.mp4')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<img src=\"logs/error.gif\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# vis depth "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 50/50 [00:03<00:00, 14.35it/s]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "GIF saved at: logs/exr_depth5.gif\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<img src=\"logs/exr_depth5.gif\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "# src= \"/baai-cwm-1/baai_cwm_ml/cwm/hong.li/code/3dgen/data/data_factory_blender/datasets/3diclight/renders_3diclightv3_eevee/ffe53ccb5519d6c3ecaf7f0661bcf15f00599d7a1d0c62568a28c9ce043a9edb\"\n",
    "# src= \"/baai-cwm-1/baai_cwm_ml/cwm/hong.li/code/3dgen/data/data_factory_blender/datasets/3diclight/renders_3diclightv3_eevee/fe0cb554503b9f2eff26a6c52cdf85f273d4a79bbfc57130cb8ffe1d72ca1e13\"\n",
    "src= \"/baai-cwm-1/baai_cwm_ml/cwm/hong.li/code/3dgen/data/data_factory_blender/datasets/3diclight/renders_3diclightv3_eevee/ffe53ccb5519d6c3ecaf7f0661bcf15f00599d7a1d0c62568a28c9ce043a9edb\"\n",
    "\n",
    "exrs = sorted(glob.glob(join(src, 'depth','*.exr')))\n",
    "save_name='logs/exr_depth5.gif'\n",
    "depth_in_exrs_to_gif(exrs, save_name)\n",
    "\n",
    "IPython.display.Image(url= save_name)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# vis normal"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 50/50 [00:06<00:00,  8.16it/s]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "GIF saved at: logs/exr_normal4.gif\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<img src=\"logs/exr_normal4.gif\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 读取法线数据\n",
    "src= \"/baai-cwm-1/baai_cwm_ml/cwm/hong.li/code/3dgen/data/data_factory_blender/datasets/3diclight/renders_3diclightv3_eevee/ffe53ccb5519d6c3ecaf7f0661bcf15f00599d7a1d0c62568a28c9ce043a9edb\"\n",
    "src= \"/baai-cwm-1/baai_cwm_ml/cwm/hong.li/code/3dgen/data/data_factory_blender/datasets/3diclight/renders_3diclightv3_eevee/fe0cb554503b9f2eff26a6c52cdf85f273d4a79bbfc57130cb8ffe1d72ca1e13\"\n",
    "src= \"/baai-cwm-1/baai_cwm_ml/cwm/hong.li/code/3dgen/data/data_factory_blender/datasets/3diclight/renders_3diclightv3_eevee/553bcb7db4be314c48462cc757edc57cdc6749434438ec8578a9428dcd728d14\"\n",
    "\n",
    "\n",
    "exrs = sorted(glob.glob(join(src, 'normal','*.exr')))\n",
    "save_path='logs/exr_normal4.gif'\n",
    "normal_in_exrs_to_gif(exrs, save_path)\n",
    "IPython.display.Image(url= save_path)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "out_name = 'logs/exr_test.gif'\n",
    "\n",
    "imgs = sorted(glob.glob(\"/baai-cwm-1/baai_cwm_ml/cwm/hong.li/code/3dgen/data/data_factory_blender/datasets/5daigc/renders_5daigc_v1/eevee/7340ff708d8736e464e98df8d9933812e10efe2ab607fd6a8d80a9be00892c13/*png\"))\n",
    "\n",
    "images_to_gif(imgs,output_gif = out_name, duration = 20)\n",
    "Image(url= out_name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<img src=\"/baai-cwm-1/baai_cwm_ml/cwm/shaocong.xu/exp/tools/logs/tmp2.gif\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.21"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
